﻿using Microsoft.EntityFrameworkCore.Migrations;

namespace OnlineLearningSystem.Repository.Migrations
{
    public partial class InitialCreate17 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Courses_Batchs_BatchID",
                table: "Courses");

            migrationBuilder.DropIndex(
                name: "IX_Courses_BatchID",
                table: "Courses");

            migrationBuilder.DropColumn(
                name: "BatchID",
                table: "Courses");

            migrationBuilder.CreateTable(
                name: "BatchCourse",
                columns: table => new
                {
                    BatchsID = table.Column<int>(type: "int", nullable: false),
                    CoursesID = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BatchCourse", x => new { x.BatchsID, x.CoursesID });
                    table.ForeignKey(
                        name: "FK_BatchCourse_Batchs_BatchsID",
                        column: x => x.BatchsID,
                        principalTable: "Batchs",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_BatchCourse_Courses_CoursesID",
                        column: x => x.CoursesID,
                        principalTable: "Courses",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_BatchCourse_CoursesID",
                table: "BatchCourse",
                column: "CoursesID");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "BatchCourse");

            migrationBuilder.AddColumn<int>(
                name: "BatchID",
                table: "Courses",
                type: "int",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_Courses_BatchID",
                table: "Courses",
                column: "BatchID");

            migrationBuilder.AddForeignKey(
                name: "FK_Courses_Batchs_BatchID",
                table: "Courses",
                column: "BatchID",
                principalTable: "Batchs",
                principalColumn: "ID",
                onDelete: ReferentialAction.Restrict);
        }
    }
}
